package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.Report;
import com.itheima.pojo.ReportCount;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
//    @Select("select e.* ,d.name deptName from emp e left join dept d on e.dept_id = d.id limit #{start},#{pageSize}")
//    List<Emp> selectpage(Integer start, Integer pageSize);
//    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id ")
//    long count();
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id ")
//    List<Emp> selectPage();

      List<Emp> selectPage(EmpQueryParam empQueryParam);
      //增加员工信息主键回显
      @Options(useGeneratedKeys = true,keyProperty = "id")
      @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time)values " +
              "(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
      void saveEmp(Emp emp);
    @Select("select *from emp")
    List<Emp> selectAll();
    //统计员工性别
    @Select("select gender name ,count(gender) value from emp group by gender")
    List<Report> genderCount();

    void deleteByIds(List<Integer> ids);
    @Select("select *from emp where id=#{id}")
    Emp selectById(Integer id);

    //根据id查询一条sql手动映射
    List<Emp> selectById2(Integer id);

    //修改员工信息
    void updateEmp(Emp emp);
//    @Select("select job from emp")
//    List<Integer> jobCount();
    @Select("select *from emp where username =#{username} and password=#{password}")
    Emp Login(Emp emp);
    @Select("select count(*) from emp where id =#{deptId}")
    long selectByEmpId(Integer deptId);

    //统计员工职位
    List<Map<String, Object>> jobCount();


//    //统计员工性别
//    @Select("select if (gender=1,'男性','女性') name,count(*) value from emp group by gender")
//    List<Map<String,Object>> genderCount();
}
